//package com.lucien.admin.controller.qiniu;
//
//import com.lucien.common.result.GlobalResult;
//import com.lucien.common.utils.StringUtils;
//import com.lucien.framework.web.qiniu.UploadService;
//import com.lucien.system.domain.SysUser;
//import com.lucien.system.service.SysUserService;
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiOperation;
//import org.apache.shiro.SecurityUtils;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.bind.annotation.PostMapping;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RequestParam;
//import org.springframework.web.bind.annotation.RestController;
//import org.springframework.web.multipart.MultipartFile;
//
//import java.io.FileInputStream;
//import java.io.IOException;
//
///**
// * @Author: Lucien
// * @Description:
// * @Date: Created in 2021/5/5
// */
//@RestController
//@RequestMapping("/qiniu")
//@Api(tags = "七牛云接口")
//public class UploadController {
//
//    @Autowired
//    private UploadService uploadService;
//
//    @Autowired
//    private SysUserService userService;
//
//    @PostMapping("/upload")
//    @ApiOperation(value = "用户上传头像")
//    public GlobalResult upload(@RequestParam("file") MultipartFile file) {
//        try {
//            SysUser loginUser = (SysUser) SecurityUtils.getSubject().getPrincipal();
//            // 获取文件名称
//            String filename = file.getOriginalFilename();
//            //生成随机照片名 防止重复名字
//            String randomImgName = StringUtils.getRandomImgName(filename);
//            if (!file.isEmpty()) {
//                FileInputStream inputStream = (FileInputStream) file.getInputStream();
//
//                String path = uploadService.uploadImg(inputStream, randomImgName);
//
//                userService.updateProfile(loginUser.getUsername(), path);
//
//                return GlobalResult.success("上传成功", path);
//            }
//            return GlobalResult.error("上传失败");
//        } catch (IOException e) {
//            return GlobalResult.error(e.getMessage());
//        }
//
//    }
//}
